<template>
	<view class="home">
		<swiper :indicator-dots="true" :circular="true" :autoplay="true" interval="3000">
			<swiper-item>
				<view class="swiper-item">
					<image src="http://m.itheima.com/images/slidead/mobile/20191210154717750-410.jpg" mode=""></image>
				</view>
			</swiper-item>
			<swiper-item class="swiper-item" v-for="item in swipers" :key="item.id">
				<view>
					<image :src="item.img"></image>
				</view>
			</swiper-item>
		</swiper>
		<!-- 导航区 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="tit">
				推荐商品
			</view>
			<goods-list @itemClick="goGoodsDetail" :goods="goods"></goods-list>
		</view>
	</view>
</template>

<script>
	import goodsList from "../../components/goods_list/goods_list.vue"
	export default {
		components: {
			goodsList
		},
		data() {
			return {
				swipers: [],
				goods: [],
				navs: [{
						icon: "iconfont icon-ziyuan",
						title: "黑马超市",
						path: '/pages/goods/goods'
					},
					{
						icon: "iconfont icon-guanyuwomen",
						title: "联系我们",
						path: '/pages/contact/contact'
					},
					{
						icon: "iconfont icon-tupian",
						title: "社区图片",
						path: '/pages/pics/pics'
					},
					{
						icon: "iconfont icon-shipin",
						title: "学习视频",
						path: '/pages/videos/videos'
					}
				]
			}
		},
		onLoad() {
			this.getSwipers()
			this.getHotGoods()
		},
		methods: {
			//获取轮播图数据
			async getSwipers() {
				const res = await this.$myRequest({
					url: '/api/getlunbo'
				})
				this.swipers = res.data.message
			},
			//获取热门商品列表数据
			async getHotGoods() {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=1'
				})
				this.goods = res.data.message
			},
			//导航点击函数
			navItemClick(path) {
				console.log(path)
				uni.navigateTo({
					url: path
				})
			},
			//跳转商品详情
			goGoodsDetail(id) {
				console.log(id, "id")
				uni.navigateTo({
					url: '/pages/goods_detail/goods_detail?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.home {
		swiper {
			width: 750rpx;
			height: 380rpx;

			image {
				width: 100%;
			}
		}

		.nav {
			display: flex;

			.nav_item {
				width: 25%;
				text-align: center;

				view {
					width: 120rpx;
					height: 120rpx;
					line-height: 120rpx;
					background-color: $shop-color;
					border-radius: 60rpx;
					margin: 20rpx auto;
					color: #FFFFFF;
					font-size: 50rpx;
				}

				.icon-tupian {
					font-size: 40rpx;
				}

				text {
					font-size: 30rpx;
				}
			}
		}

		.hot_goods {
			background-color: #eee;
			overflow: hidden;
			margin-top: 10px;

			.tit {
				height: 50px;
				line-height: 50px;
				font-size: 20px;
				color: $shop-color;
				text-align: center;
				letter-spacing: 20px;
				background-color: #FFFFFF;
				margin: 7rpx 0;
			}
		}
	}
</style>
